package cn.ad.server.persistence.dao;

import cn.ad.server.domain.ad.AdTemplateSpec;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface AdTemplateSpecDao {

	@Results(value = {@Result(column = "id", property = "id", id = true),
			/*@Result(column = "template_id", property = "adTemplate.id"),*/
			@Result(column = "template_id", property = "adTemplateId"),
			@Result(column = "element_type", property = "elementType"),
			@Result(column = "index_value", property = "indexValue"),
			@Result(column = "min_length", property = "minLength"),
			@Result(column = "max_length", property = "maxLength"),
			@Result(column = "action_type", property = "actionType"),
			@Result(column = "create_time", property = "createTime"),
			@Result(column = "update_time", property = "updateTime")})
	@Select("select * from ad_template_spec")
	List<AdTemplateSpec> findAll();

	@Results(value = { @Result(column = "id", property = "id", id = true),
			@Result(column = "template_id", property = "adTemplate.id"),
			@Result(column = "element_type", property = "elementType"),
			@Result(column = "index_value", property = "indexValue"),
			@Result(column = "min_length", property = "minLength"),
			@Result(column = "max_length", property = "maxLength"),
			@Result(column = "action_type", property = "actionType"),
			@Result(column = "create_time", property = "createTime"),
			@Result(column = "update_time", property = "updateTime") })
	@Select("select * from ad_template_spec where update_time >= #{value}")
	List<AdTemplateSpec> findAfterTime(String warmUpTime);

	@Results(value = { @Result(column = "id", property = "id", id = true),
			@Result(column = "template_id", property = "adTemplate.id"),
			@Result(column = "element_type", property = "elementType"),
			@Result(column = "index_value", property = "indexValue"),
			@Result(column = "min_length", property = "minLength"),
			@Result(column = "max_length", property = "maxLength"),
			@Result(column = "action_type", property = "actionType"),
			@Result(column = "format_type", property = "formatType"),
			@Result(column = "create_time", property = "createTime"),
			@Result(column = "update_time", property = "updateTime") })
	@Select("select * from ad_template_spec where id = #{value}")
	AdTemplateSpec findById(long id);
	
	@Results(value = { @Result(column = "id", property = "id", id = true),
			@Result(column = "template_id", property = "adTemplate.id"),
			@Result(column = "element_type", property = "elementType"),
			@Result(column = "index_value", property = "indexValue"),
			@Result(column = "min_length", property = "minLength"),
			@Result(column = "max_length", property = "maxLength"),
			@Result(column = "action_type", property = "actionType"),
			@Result(column = "format_type", property = "formatType"),
			@Result(column = "create_time", property = "createTime"),
			@Result(column = "update_time", property = "updateTime") })
	@Select("select * from ad_template_spec where id = #{id} and status = #{status}")
	AdTemplateSpec selectById(@Param("id")long id, @Param("status")int status);
	
	
	@Results(value = {@Result(column = "id", property = "id", id = true),
			/*@Result(column = "template_id", property = "adTemplate.id"),*/
			@Result(column = "element_type", property = "elementType"),
			@Result(column = "index_value", property = "indexValue"),
			@Result(column = "min_length", property = "minLength"),
			@Result(column = "max_length", property = "maxLength"),
			@Result(column = "action_type", property = "actionType"),
			@Result(column = "create_time", property = "createTime"),
			@Result(column = "update_time", property = "updateTime")})
	@Select("select * from ad_template_spec where template_id = #{value} and status = 1")
	List<AdTemplateSpec> findByTemplateId(int tid);
	
}
